/*
int
parse 5 5
parse 2+3 5
parse '2*3' 6
parse '2+3+4' 9
parse '2*3+4' 10
parse '2+3*4' 14
parse '2*3*4' 24
parse 456 456
parse '53*(13+75)' 4664
parse ' 456 + 123 * ( 543 + 7 * (987 + 2) + 6) ' 919512
parse -3 -3
parse 3-2 1
parse 3-2-1 2
noparse x Sum 1
noparse '2 + ' Additive 5
*/

# Bryan Ford's trivial grammar with (possibly negative) integers, subtraction,
# spacing, repetitions, and character classes.

Sum :: int ← Space a:Additive End → a
Additive ← m:Multitive Plus a:Additive { m + a }
	/ m:Multitive Minus a:Additive { m + -a }
	/ m:Multitive -> m
Multitive ← p:Primary Times m:Multitive { p * m } / p:Primary -> p
Primary ← Left a:Additive Right -> a / d:Decimal -> d
Decimal ← "-"? Digit+ Space { atoi(ref_ptr(ref())) }
Digit :: void ← [0-9]

Left ← "(" Space
Right ← ")" Space
Plus ← "+" Space
Minus ← "-" Space
Times ← "*" Space
Space ← " " *
End ← ! .
